package com.ybg.user.business.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ybg.common.entity.Message;
import com.ybg.user.business.entity.FrontUserInfo;
import com.ybg.user.business.entity.LoginEmployee;
import com.ybg.user.business.entity.UserInfo;
import com.ybg.user.business.mapper.FrontUserMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class FrontUserService extends ServiceImpl<FrontUserMapper, FrontUserInfo> {

    public Message adminUserPage(int pageNo, int pageSize){
        pageNo = Math.max(pageNo, 1);
        pageSize = pageSize<10 ? 5 : pageSize>50 ? 50 : (pageSize/10)*10;
        try {
            List<FrontUserInfo> records = super.baseMapper.adminUserPage((pageNo-1)*pageSize, pageSize);
            int pages = (int)Math.ceil(super.count() * 1.0 /pageSize);
            Map<String,Object> page = new HashMap<>(3);
            page.put("current",pageNo);
            page.put("size",pageSize);
            page.put("pages",pages);
            page.put("records",records);
            return Message.succeed(page);
        }catch (Exception e){
            log.error("管理员分页查询账户信息异常",e);
            return Message.error(e);
        }
    }
}
